package com.isoftstone.common.base;

import com.isoftstone.util.NumUtil;
import org.apache.commons.fileupload.ProgressListener;
import org.apache.shiro.session.Session;

/**
 * 类名称：文件进度监听器
 *
 * @author：guoX
 * @date: 2016/6/6
 */
public class FileProcessListener implements ProgressListener{
    private Session session = SessionManager.getSession();
    public FileProcessListener(){}

    public FileProcessListener(Session session) {
        this.session=session;
    }

    /**
     * 计算上传进度数
     * pBytesRead 到目前为止读取文件的比特数   pContentLength 文件总大小 pItems 目前正在读取第几个文件
     */
    public void update(long pBytesRead, long pContentLength, int pItems) {

        /*System.out.println(NumUtil.getPercent(pBytesRead, pContentLength) + "ddddddddddddddddddddd");*/
        session.setAttribute("upload_ps", NumUtil.getPercent(pBytesRead, pContentLength));
    }

}
